<template>
	<view>
		<web-view :webview-styles="webviewStyles" :src="url" @message="handleMessage"></web-view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import payApi from '../../api/pay';

	const user = JSON.parse(uni.getStorageSync("app"))
	const tmpUser = {
		Account: user.account
	};
	const url = ref("");
	const webviewStyles = {
		progress: {
			color: '#FF3333'
		}
	};
	onLoad(options => {
		// url.value = decodeURIComponent(options.url) + "?user=" + encodeURIComponent(JSON.stringify(tmpUser));
		// url.value = decodeURIComponent(options.url) + "?userinfo="+encodeURIComponent(JSON.stringify(user));
		url.value = decodeURIComponent(options.url) + "?account=" + user.account;
		console.log(url.value);
	})

	const handleMessage = (event) => {
		const res = event.detail.data;
		console.log(res);
		let orderbh = ""
		if (res.length) {
			res.map(item => {
				orderbh = item.orderbh
			})
		}
		if (orderbh) {
			// 
			getPayConfig(orderbh)
		}
	}

	const getPayConfig = async (orderbh) => {
		let req = {
			app: 4,
			"account": user.account,
			"comId": user.comId,
			"orderNum": orderbh,
			"payType": "miniapp",
			"feeType": "物业费",
		}
		const res = await payApi.getPayConfig(req);
		console.log(res);
		const payRes = JSON.parse(res.data);
		console.log(payRes);
		
	}
</script>

<style>

</style>